package cn.jiyun.service.impl;

import cn.jiyun.model.pojo.Coupon;
import cn.jiyun.service.ICouponService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.jiyun.mapper.CouponMapper;
import cn.jiyun.model.query.CouponQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.List;

/**
 * 针对表【-Coupon】的业务操作的Service实现类
 *
 * @author
 * @since 2024-12-18
 */
@Service
public class CouponServiceImpl extends ServiceImpl<CouponMapper, Coupon> implements ICouponService {

    private final CouponMapper couponMapper;

    public CouponServiceImpl(CouponMapper couponMapper) {
        this.couponMapper = couponMapper;
    }

    @Override
    public IPage<Coupon> getPageList(CouponQuery query){
        //1.创建查询条件
        QueryWrapper<Coupon> qw = new QueryWrapper<>();
        //ToDo 查询条件

        //2.组件分页数据
        IPage<Coupon> page = new Page<>(query.getCurrentPage(), query.getPageSize());
        //3.查询
        baseMapper.selectPage(page,qw);
        //4.返回
        return page;
    }

    @Override
    public List<Coupon> getCoupon(Long id,Integer status) {
        String statuss="";
        if(status==1){
             statuss="已过期";
        }
        if(status==2){
             statuss="已使用";
        }
        if(status==0){
            return couponMapper.getCoupons(id);
        }
        return couponMapper.getCoupon(id, statuss);
    }
}
